#pragma once

#include <iostream>
#include <string>
#include <sstream>
#include "Util.hpp"

using namespace std;

const string sep = "\r\n";

const string default_path = "./wwwroot";

const string home_page = "index.html";  // 默认首页

class HttpRequest
{
public:
    HttpRequest()
    {}
    ~HttpRequest()
    {}

    void parse()
    {
        string line = Util::getOneLine(inbuffer, sep);
        if(line.empty()) return;

        cout << "line: " << line << endl;

        stringstream ss(line);

        ss >> method >> url >> httpversion;

        path = default_path;
        path += url;    // ---> ./wwwroot/a/b/c  or ./wwwroot/

        if(path[path.size() - 1] == '/')
            path += home_page;
    }

public:
    string inbuffer;

    string method;
    string url;
    string path;
    string httpversion;
};

class HttpResponse
{
public:
    string outbuffer;
};